<template>
  <div class="content content41">
    <!-- <div>
      检测条件：温度T：<el-input v-model="form.temperature" class="input-line" />℃；气压p：<el-input v-model="form.pressure" class="input-line" />Kpa
    </div> -->
    <div class="innertitle">
      1.空间分辨率
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td colspan="2">检测项目</td>
        <td colspan="16">检测结果</td>
      </tr>
      <tr>
        <td rowspan="2" colspan="2">空间分辨率</td>
        <td colspan="4">源位置</td>
        <td>1cm处经向</td>
        <td>1cm处切向</td>
        <td>1cm处横向</td>
        <td>1cm处轴向</td>
        <td>10cm处经向</td>
        <td>10cm处切向</td>
        <td>10cm处横向</td>
        <td>10cm处轴向</td>
        <td>20cm处经向</td>
        <td>20cm处切向</td>
        <td>20cm处横向</td>
        <td>20cm处轴向</td>
      </tr>
      <tr>
        <td colspan="4">平面宽FWHM（mm）</td>
        <td><el-input v-model="form.spatialResolution.radial_1" class="input-line" /></td>
        <td><el-input v-model="form.spatialResolution.tangential_1" class="input-line" /></td>
        <td><el-input v-model="form.spatialResolution.crossSection_1" class="input-line" /></td>
        <td><el-input v-model="form.spatialResolution.axial_1" class="input-line" /></td>
        <td><el-input v-model="form.spatialResolution.radial_10" class="input-line" /></td>
        <td><el-input v-model="form.spatialResolution.tangential_10" class="input-line" /></td>
        <td><el-input v-model="form.spatialResolution.crossSection_10" class="input-line" /></td>
        <td><el-input v-model="form.spatialResolution.axial_10" class="input-line" /></td>
        <td><el-input v-model="form.spatialResolution.radial_20" class="input-line" /></td>
        <td><el-input v-model="form.spatialResolution.tangential_20" class="input-line" /></td>
        <td><el-input v-model="form.spatialResolution.crossSection_20" class="input-line" /></td>
        <td><el-input v-model="form.spatialResolution.axial_20" class="input-line" /></td>
      </tr>
    </table>
    <div class="innertitle">
      2.断层成像灵敏度
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>检测项目</td>
        <td colspan="8">检测结果</td>
      </tr>
      <tr>
        <td rowspan="3">灵敏度</td>
        <td colspan="2">线源长度（cm）</td>
        <td colspan="6"><el-input v-model="form.sensitivity.length" class="input-line" /></td>
      </tr>
      <tr>
        <td>总活度（<i>$\mu$</i>Ci）</td>
        <td><el-input v-model="form.sensitivity.countActivity" class="input-line" /></td>
        <td>总活度测量时间</td>
        <td><el-input v-model="form.sensitivity.countActivityTestTime" class="input-line" /></td>
        <td>剩余活度（<i>$\mu$</i>Ci）</td>
        <td><el-input v-model="form.sensitivity.surplusActivity" class="input-line" /></td>
        <td>剩余活度测量时间</td>
        <td><el-input v-model="form.sensitivity.surplusActivityTestTime" class="input-line" /></td>
      </tr>
      <tr>
        <td><i>$S_{0}$</i>（cps/kBq）</td>
        <td><el-input v-model="form.sensitivity.sensitivity_0" class="input-line" /></td>
        <td><i>$S_{10}$</i>（cps/kBq）</td>
        <td><el-input v-model="form.sensitivity.sensitivity_10" class="input-line" /></td>
        <td colspan="2"><i>$S_{av} = ( S_{0} + S_{10} ) / 2 $</i>（cps/kBq）</td>
        <td colspan="2" class="result"><el-input v-model="form.sensitivity.sensitivity_average" class="input-line" disabled /></td>
      </tr>
    </table>

    <div class="innertitle">
      3.噪声等效计数率、散射分数、准确性:计数丢失和随机符合校正、飞行时间分辨力
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>检测项目</td>
        <td colspan="8">检测结果</td>
      </tr>
      <tr>
        <td rowspan="4">
          噪声等效计数率、散射分数、准确性:计数丢失和随机符合校正、飞行时间分辨力
        </td>
        <td colspan="2">线源长度（cm）</td>
        <td colspan="6"><el-input v-model="form.other.length" class="input-line" /></td>
      </tr>
      <tr>
        <td>总活度（mCi）</td>
        <td><el-input v-model="form.other.countActivity" class="input-line" /></td>
        <td>总活度测量时间</td>
        <td><el-input v-model="form.other.countActivityTestTime" class="input-line" /></td>
        <td>剩余活度（mCi）</td>
        <td><el-input v-model="form.other.surplusActivity" class="input-line" /></td>
        <td>剩余活度测量时间</td>
        <td><el-input v-model="form.other.surplusActivityTestTime" class="input-line" /></td>
      </tr>
      <tr>
        <td colspan="2">噪声等效计数率（cps）</td>
        <td colspan="2"><el-input v-model="form.other.countingRate" class="input-line" /></td>
        <td colspan="2">散射分数</td>
        <td colspan="2"><el-input v-model="form.other.scatterFraction" class="input-line" /></td>
      </tr>
      <tr>
        <td colspan="2">准确性:计数丢失和随机符合校正</td>
        <td colspan="2"><el-input v-model="form.other.accuracyCountLossRandom" class="input-line" /></td>
        <td colspan="2">飞行时间分辨力（ps）</td>
        <td colspan="2"><el-input v-model="form.other.flightTimeResolution" class="input-line" /></td>
      </tr>
    </table>
  </div>
</template>

<script>
  import {getInfoById, postInfo} from '@/api/testItem/item41'
  export default{
    data(){
      return{
        timeList:[],
        hourList:[],
        initFlag:false,
        spatialResolution:{
          action:'resolution',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:[],
          like:false
        },
        "sensitivity": {
          action:'sensitivity',
          flag:true,
          loading:false,
          notNumber:['countActivityTestTime','surplusActivityTestTime'],
          intNumber:[],
          like:false
        },
        "other": {
          action:'other',
          flag:true,
          loading:false,
          notNumber:['countActivityTestTime', 'surplusActivityTestTime'],
          intNumber:[],
          like:false
        },
        "form": {
          "itemsId": 0,
          "resultId": 0,
          "temperature": 0.0,
          "pressure": 0.0,
          "spatialResolution": {
          }, // 空间分辨率
          "sensitivity": {
          }, // 灵敏度
          "other": {
          }, // 
        }
      }
    },
    props: {
    	// tab栏
      activeNameEquipment: {
    		type: String,
        default: "0",
      },
    	// 基本信息数据
      basicForm: {
    		type: Object,
        default: () => {
    			return {}
    		},
      },
    },
    methods:{
      setTime(){
        for (let index = 0; index < 60; index++) {
        	let t = index;
        	if (t < 10) {
        		t = "0" + index;
        	}else {
        		t = "" + index;
        	}
        	this.timeList.push({
        		label: t,
        		value: t,
        	})
          if(index < 24){
            this.hourList.push({
            	label: t,
            	value: t,
            })
          }
        }
      },
      //修改数据
      setData(name,data){
        // if(name == 'tomographySensitivity' || name == 'scatterFraction'){
        //   let activityTime = data.activityTime?.split(':') || [];
        //   data.activityHour = activityTime[0];
        //   data.activityMinute = activityTime[1];
        //   let startCollectionTime = data.startCollectionTime?.split(':') || [];
        //   data.startCollectionHour = startCollectionTime[0];
        //   data.startCollectionMinute = startCollectionTime[1];
        // }
        this.form[name] = data ? data : (this[name] ? {}:null);
      },
      //表单修改提交后端
       postForm(param,name){
         param['itemsId'] = this.form.itemsId;
        //  if(name == 'tomographySensitivity' || name == 'scatterFraction'){
        //    let activityTime = param.activityHour ? param.activityHour :'';
        //    activityTime += ":";
        //    activityTime += param.activityMinute ? param.activityMinute :'';
        //    param['activityTime'] = activityTime;
        //    let startCollectionTime = param.startCollectionHour ? param.startCollectionHour :'';
        //    startCollectionTime += ":";
        //    startCollectionTime += param.startCollectionMinute ? param.startCollectionMinute :'';
        //    param['startCollectionTime'] = startCollectionTime;
        //  }
         this.$emit("loadingchange", true);
      	 postInfo(param,this[name].action).then(res=>{
      		 this.$emit("loadingchange", false);
      		 if(res.code == 200){
      			 this[name].flag = false;
      			 if(name != 'sdd'){
      				this.setData(name,res.data);
      			 }
      		 }
      	 })
      },
      validateType(arr,keys,obj){
      	if(obj.like){
      		for(let i=0;i<arr.length;i++){
      			if(keys.indexOf(arr[i]) != -1){
      				return true;
      			}
      		}
      		return false;
      	}else{
      		if(arr.indexOf(keys) != -1){
      			return true;
      		}
      		return false;
      	}
      },
       //数据验证
       validateData(newName,myName){
      	 if(!this[myName].noClear){
      		clearTimeout(this[myName].loading);
      	 }else{
      		 this[myName].noClear = false;
      	 }
         let regNumber = /^[-]?\d*([.](\d+))?$/;//小数验证正则
         let regRepNumber = /[^-?\d.,]/g;//将除小数外的符号消除正则
         let regInt = /^\d*$/;//整数验证正则
         let regRepInt = /[^-?\d,]/g;//将除小数外的符号消除正则
         let reg,regRep;
         let repStr = '';
      	 let intResult
         if(JSON.stringify(newName) != '{}'){
           //遍历该对象所有字段进行验证
           for(let keys in newName){
             //数字验证环节
      			 if((typeof newName[keys] == 'string') ||  (typeof newName[keys] == 'number')){
      				if(newName[keys] && !this.validateType(this[myName].notNumber,keys,this[myName])){
      					intResult = this.validateType(this[myName].intNumber,keys,this[myName]);
      					reg = intResult ? regInt:regNumber;
      				  let bool = !reg.test(newName[keys]);
      				  if(bool){
      						setTimeout(()=>{
      							intResult = this.validateType(this[myName].intNumber,keys,this[myName]);
      							regRep = intResult ? regRepInt:regRepNumber;
      									repStr = newName[keys] + '';
      							repStr =  repStr.replace(regRep,'');
      							if(repStr != (newName[keys]+'')){
      								if(!this[myName].noClear){
      									this[myName].noClear = true;
      								}
      								newName[keys] = repStr;
      							}
      						},100);
      						if(this[myName].flag){
      						 this[myName].flag = false;//如果数字验证不通过不需要请求后端
      						}
      				  }
      				}
      			 }
           }
      		 this.isPost(newName,myName);
         }
       },
       isPost(newName,myName){
      	 if(this[myName].flag){//是否请求后端判断
      	  let postBody = {};
      	  for(let i in newName){
      	    if(newName[i] !== null && newName[i] !== undefined){
      	      postBody[i] = newName[i];
      	    }
      	  }
      	  if(JSON.stringify(postBody) != '{}'){
      			this[myName].loading = setTimeout(()=>{
      				this.postForm(postBody,myName);
      			},800)
      	  }
      	 }else{
      		 this[myName].flag = true;
      	 }
       },
    },
    watch:{
      activeNameEquipment: {
        handler(val) {
          this.$nextTick(()=>{
            let resultId = this.basicForm.resultId;
            getInfoById(resultId).then(response => {
              if(response.code == 200){
                let data = response.data;
                for(let keys in data){
                  // this.form[keys] = data[keys] ? data[keys] : (this[keys] ? {}:null);
                  this.setData(keys,data[keys]);
                }
                 setTimeout(()=>{
                   this.initFlag = true;
                 },300)
              }
            }).catch((response) => {
               this.$emit("loadingchange", true);
             });
             });
          this.setTime();
        },
        deep: true,
        immediate: true
      },
      "form.spatialResolution":{
        handler(newName, oldName) {
          console.log(newName);
         if(this.initFlag){
          this.validateData(newName,'spatialResolution');
         }
        },
        deep:true,
        immediate: true
      },
      "form.sensitivity":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'sensitivity');
         }
        },
        deep:true,
        immediate: true
      },
      "form.other":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'other');
         }
        },
        deep:true,
        immediate: true
      },
    }
  }
</script>

<style lang="scss" scoped>
  @import '../content.scss';

  .miniFont {
    font-size: 10px;
  }
  .el-select{
    width: 50px;
  }
  .miniFontCenter {
    margin-top: 8px;
  }

  .content41 {
    padding-inline: 0 !important;

    table {
      table-layout: fixed;
      width: 100%;

      td {
        max-width: 100px;

        ::v-deep .el-checkbox__label {
          white-space: break-spaces;
        }
      }

      .el-input {
        width: 100% !important;
      }

      .multipleInput {
        .el-input {
          width: 50px !important;
        }
      }
    }

    .innertitle {
      display: block;
      margin-left: 0;
    }

    .table1 {
      .el-radio {
        display: flex;
        align-items: center;
      }
    }

    #hearderTR td:nth-child(7) {
      display: none;
    }
  }
</style>
